global input "Q:\dc1prhcmsas01\PU2\data - sas"
global temp "Q:\dc1prhcmsas01\PU2\temp_stata_wr"
global log "Q:\dc1prhcmsas01\PU2\Log - Stata WR"
global output "Q:\dc1prhcmsas01\PU2\data_stata_wr"
global graphs "Q:\dc1prhcmsas01\PU2\graphs_stata_wr"
global tables "Q:\dc1prhcmsas01\PU2\tables_stata_wr"

cd "Q:\dc1prhcmsas01\PU2\Code - Stata WR"

capture log close
log using "$log/6_fig_panel_diff_distribution_40bin", replace

set scheme plotplain
graph set window fontface "Times New Roman"


*Fig 2:
	*Calculate share in treated, collapse by date, difference relative to April 2016
	use "$output\stayers_distribution_treat.dta", clear
	keep if yr_month>=mdy(01,01,2016) & yr_month<=mdy(12,01,2017)
	replace bin=floor((bin-913)/40)*40+913
	collapse (sum) n, by(yr_month client_id salaried0 bin)
	bysort yr_month client_id salaried0: egen emp=sum(n)
	gen share=n/emp
	collapse (mean) share, by(yr_month salaried0 bin)
	drop if bin<=0 | bin>2000
	
	preserve 
		keep if yr_month==mdy(4,01,2016)
		rename share share0 
		drop yr_month
		tempfile temp 
		save `temp'
	restore 
	
	merge m:1 salaried0 bin using `temp'
	drop _merge 
	gen diff_share1=share-share0
	gen time=mofd(yr_month)-mofd(mdy(4,01,2016))
	
	tempfile treat
	save `treat'
	
	*Calculate share in control, collapse by date, difference relative to April 2014
	use "$output\stayers_distribution_control.dta", clear
	keep if yr_month>=mdy(01,01,2014) & yr_month<=mdy(12,01,2015)
	replace bin=floor((bin-913)/40)*40+913
	collapse (sum) n, by(yr_month client_id salaried0 bin)
	bysort yr_month client_id salaried0: egen emp=sum(n)
	gen share=n/emp
	collapse (mean) share, by(yr_month salaried0 bin)
	drop if bin<=0 | bin>2000
	
	preserve 
		keep if yr_month==mdy(4,01,2014)
		rename share share0 
		drop yr_month
		tempfile temp 
		save `temp'
	restore 
	
	merge m:1 salaried0 bin using `temp'
	drop _merge 
	gen diff_share0=share-share0
	gen time=mofd(yr_month)-mofd(mdy(4,01,2014))

	*Diff-in-diff
	merge 1:1 time salaried bin using `treat'
	gen diff_diff=diff_share1-diff_share0
	
	*Label each month for graph
	label define time_lab -3 "Jan 2016" -2 "Feb 2016" -1 "Mar 2016" 0 "Apr 2016" 1 "May 2016" 2 "Jun 2016" ///
		3 "Jul 2016" 4 "Aug 2016" 5 "Sep 2016" 6 "Oct 2016" 7 "Nov 2016" 8 "Dec 2016" ///
		9 "Jan 2017" 10 "Feb 2017" 11 "Mar 2017" 12 "Apr 2017" 13 "May 2017" 14 "Jun 2017" ///
		15 "Jul 2017" 16 "Aug 2017" 17 "Sep 2017" 18 "Oct 2017" 19 "Nov 2017" 20 "Dec 2017", replace
	label values time time_lab 
	
	*Plot 
	graph twoway (connect diff_diff bin if salaried==1, by(time, rows(4) note("")) lc(black) mcolor(black)), ///
		xline(455, lcolor(black)) xline(913, lcolor(red)) xtitle("Weekly Base Pay") xscale(off) ///
		ytitle("Effect on Share of Salaried Workers") ylabel(-0.005(0.0025)0.01, nogextend) plotregion(lcolor(black)) 
	graph export "$graphs/fig2_panel_salaried_40bin.eps", replace
	graph export "$graphs/fig2_panel_salaried_40bin.jpg", replace
	
	graph twoway (connect diff_diff bin if salaried==0, by(time, rows(4) note("")) lc(black) mcolor(black)), ///
		xline(455, lcolor(black)) xline(913, lcolor(red)) xtitle("Weekly Base Pay") xscale(off) ///
		ytitle("Effect on Share of Hourly Workers") ylabel(-0.005(0.0025)0.01, nogextend) plotregion(lcolor(black)) 
	graph export "$graphs/fig2_panel_hourly_40bin.eps", replace
	graph export "$graphs/fig2_panel_hourly_40bin.jpg", replace
	
log close 

